package aes.gui;

import java.awt.CardLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.JTextPane;

import aes.general.GuiControlBeta;
import aes.general.StudentControl;


/**
 * The Class StudentExamPanel. Opened after student selects the Automatic Exam Execution.
 * Prompts for Student Id before he can start the Exam.
 */
public class StudentExamPanel extends JPanel {

	
	private static final long serialVersionUID = 1L;
	private JPanel jp;
	private JLabel l1;
	private JLabel l2;
	private JTextField t1;
	private JButton b1;
	private String ActivCode=null;

	/**
	 * Create the panel.
	 *
	 * @param contentPane the content pane
	 * @param Code the Activation code
	 */
	public StudentExamPanel(JPanel contentPane, String Code) {
		this.jp = contentPane;
		this.ActivCode=Code;
		initialize();
	}

	/**
	 * Initialize.
	 */
	public void initialize() {
		setLayout(null);
		
		l1 = new JLabel("Start Automated Exam");
		l1.setFont(new Font("Tempus Sans ITC", Font.BOLD, 21));
		l1.setBounds(193, 11, 266, 29);
		add(l1);
		
		JSeparator separator = new JSeparator();
		separator.setBounds(10, 38, 620, 2);
		add(separator);
		
		l2 = new JLabel("Enter Your ID and click  \"Next\" button. ");
		l2.setFont(new Font("Tahoma", Font.BOLD, 16));
		l2.setBounds(157, 71, 424, 17);
		add(l2);
		
		t1 = new JTextField();
		t1.setBounds(262, 99, 94, 20);
		add(t1);
		t1.setColumns(10);
				
		b1 = new JButton("Next");
		b1.setBounds(340, 387, 129, 23);
		add(b1);
		b1.addActionListener(new ActionListener() {
		

			public void actionPerformed(ActionEvent e) {
				
			//	StudentControl.CheckUserID(t1.getText());
			
			if (t1.getText().trim().length()==0)
			{
				JOptionPane.showMessageDialog(null,
					"Please enter your User ID", "Error",
					JOptionPane.ERROR_MESSAGE);
				return;
			}

			if (t1.getText().equals(GuiControlBeta.userid))	
				
			{
				
				StudentControl.DownloadExamAutomaticQuery(ActivCode);
				return;		
				
			}
				
			JOptionPane.showMessageDialog(null,
						"ERROR , Wrong UserID .", "Error",
						JOptionPane.ERROR_MESSAGE);
				
				
			}
		});
		
		JButton b3 = new JButton("Back");
		b3.setBounds(150, 387, 129, 23);
		add(b3);
		
		JLabel lblYouWillStart = new JLabel("You will start the exam instantly after you click \"Next\" button");
		lblYouWillStart.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblYouWillStart.setBounds(40, 200, 490, 17);
		add(lblYouWillStart);
		
		JLabel lblGoodLuck = new JLabel("Good Luck!");
		lblGoodLuck.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblGoodLuck.setBounds(251, 280, 137, 17);
		add(lblGoodLuck);
		b3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				CardLayout cl = (CardLayout)(jp.getLayout());
				 cl.show(jp,"MainPanel");	}
		});
	}
}
